package com.example.arithmeticleetcode.leetcode.September;

import javax.lang.model.element.VariableElement;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-09-27 10:51
 **/
public class Demo21 {

    public static void main(String[] args) {
        System.out.println(divideNumber(new BigDecimal(197.5)));
        System.out.println(divideNumber(new BigDecimal(200.5)));
        System.out.println(divideNumber(new BigDecimal(200.25)));
    }

    public static List<BigDecimal>  divideNumber(BigDecimal number) {
        if (number == null || number.compareTo(new BigDecimal("0")) <= 0) {
            return null;
        }
        BigDecimal integerValue = new BigDecimal(Double.toString(number.longValue()));
        BigDecimal decimalValue = number.subtract(integerValue);
        BigDecimal divideValue = integerValue.divide(new BigDecimal(2));
        BigDecimal result1 = divideValue.setScale(0, BigDecimal.ROUND_UP);
        BigDecimal result2 = divideValue.setScale(0, BigDecimal.ROUND_DOWN).add(decimalValue);
        return Arrays.asList(result1, result2);
    }
}
